<!DOCTYPE html>
<html>
<head>
<include file="Home@public/link" />
<title>购物车</title>
</head>
<body>
<!--顶部图层-->
<include file="Home@public/head1" />
<!--购物车样式-->
<div class="Inside_pages">
    <div class="Process_img">
        <img src="STRING_INDEX/images/Process_img_01.png" />
    </div>
    <if condition="$num gt 0">
    <div class="content mar_20">
    <form action="{$order}" method="post" id="form">
        <table border="0" class="car_tab" style="width:1200px; margin-bottom:50px;" cellspacing="0" cellpadding="0">
            <thead>
                <tr>
                    <!-- <td><input type="checkbox" name="">全选</td> -->
                    <td class="car_th" width="490">商品名称</td>
                    <!-- <td class="car_th" width="140">属性</td> -->
                    <td class="car_th" width="150">购买数量</td>
                    <td class="car_th" width="130">小计</td>
                    <!-- <td class="car_th" width="140">返还积分</td> -->
                    <td class="car_th" width="150">操作</td>
                </tr>
            </thead>
            <tbody id="tbody">
                <?php $i=0; ?>
                <volist name="buycart" id="vo" key="k">
                <tr><!-- 
                    <td style="width: 20px;">
                        <input type="checkbox" name=""> -->
                        <input type="hidden" name="cart[{$k}][id]" value="{$vo['id']}" class="cartid">
                    <!-- </td>      -->
                    <td>
                        <div class="c_s_img"><img src="STRING_PRODUCT/{$vo['photos']}" width="73" height="73"></div>
                        <div class="merchandise">{$vo['merchandise']}</div>
                        <div style="margin-top: 20px;color:#ff4e00;font-size: 18px;" >
                            <i style="font-size:20px; color:#ff4e00;">￥</i>
                            <i class="price">{$vo['price']}</i>
                        </div>
                    </td>
                    <!-- <td align="center">颜色：灰色</td> -->
                    <td align="center">
                        <div class="c_num">
                            <input type="button" value="-" class="car_btn_1 reduce" />
                            <input type="text" value="{$vo['number']}" name="cart[{$k}][number]" class="car_ipt"  />  
                            <input type="button" value="+" class="car_btn_2 add" />
                        </div>
                    </td>
                    <td align="center" style="color:#ff4e00;font-size: 18px;" ><i style="font-size:22px; color:#ff4e00;">￥</i><i class="sum" name="sumtotal"><php>echo $vo['number']*$vo['price'];</php></i></td>
                    <!-- <td align="center">26R</td> -->
                    <td align="center"><a onclick="ShowDiv('MyDiv','fade')">删除</a>&nbsp; &nbsp;<a href="#">加入收藏</a></td>
                </tr>
                <?php $i=$i+$vo['number']*$vo['price']; ?>
                </volist>
            </tbody>
                <tr height="70">
                    <td colspan="6" style="font-family:'Microsoft YaHei'; border-bottom:0;">
                        <label class="r_rad"><input type="checkbox" name="clear" checked="checked"></label><label class="r_txt">清空购物车</label>
                        <span class="fr">商品总价：<i style="font-size:22px; color:#ff4e00;">￥</i><b style="font-size:22px; color:#ff4e00;" id="total" name="total"><?php echo $i; ?></b></span>
                    </td>
                </tr>
                <tr valign="top" height="150">
                    <td colspan="6" align="right">
                        <a href="{$product}"><img src="STRING_INDEX/images/buy1.gif"></a>&nbsp; &nbsp; 
                        <a id="pay"><img src="STRING_INDEX/images/buy2.gif"></a>
                        <!-- <button><img src="STRING_INDEX/images/buy2.gif"></button> -->
                    </td>
                </tr>        
        </table>
        </form>
    </div>
    <else/>
        <div class="content mar_20">
            <div class="nogoods"><b style="background-image: url(STRING_INDEX/images/settleup-nogoods.png)"></b><h1 align="center">购物车中还没有商品，赶紧选购吧！</h1></div>
            <table border="0" class="car_tab" style="width:1200px; margin-bottom:50px;" cellspacing="0" cellpadding="0">
            <tr valign="top" height="150">
                    <td colspan="6" align="center" ">
                        <a href="{$product}"><img src="STRING_INDEX/images/buy1.gif" style="font-size: 3em;"></a>
                    </td>
                </tr>
            </table>
        </div>
    </if>
</div>
<include file="Home@public/right" /> 
<script type="text/javascript">
    $('.add').on('click',function(){
        var a=$(this).parent().find('.car_ipt');
        var num=parseInt($(a).val());
        var price =$(this).parent().parent().parent().find('.price').text();
        price=parseFloat(price);
        num++;
        $(a).val(num);
        var sumtotal = price*num;
        sumtotal=sumtotal.toFixed(2);
        var sum=$(this).parent().parent().next().find('.sum');
        $(sum).text(sumtotal);
        sumTotal();
    });
    $('.reduce').on('click',function(){
        var a=$(this).parent().find('.car_ipt');
        var num=parseInt($(a).val());            
        var price =$(this).parent().parent().parent().find('.price').text();
        price=parseFloat(price);
        if (num>1) {
            num--; 
            $(a).val(num);
            var sumtotal = price*num;
            sumtotal=sumtotal.toFixed(2);
            var sum=$(this).parent().parent().next().find('.sum');
            $(sum).text(sumtotal);
            sumTotal();
        }
    });
    function sumTotal(){
        var tr=$('#tbody tr');
        var total=0;
        for (var i = 0; i < tr.length; i++) {
            var num=parseInt($(tr[i]).find('.car_ipt').val());
            var price =parseFloat($(tr[i]).find('.price').text());
            total=total+(price*num);
        }
        total=total.toFixed(2);
        $('#total').text(total);
    }
    $('#pay').on('click',function(){
        $('#form').submit();
        return false;
    });
</script>
</body>
</html>
